<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">

    <link rel="stylesheet" href="../layui/css/layui.css">
    <script src="../layui/layui.js"></script>
    <script src="../scripts/jquery.min.js"></script>
    <script src="../js/jquery-form.js"></script>

    <title>资讯信息修改</title>
    <style>
        body{padding: 10px;}
        .change_size{
            height: 200px;
        }
    </style>
</head>

<body>

<input type="hidden" id="flag_manager" value=<%=session.getAttribute("flag_manager")%> />


<input type="hidden" id="flag_edit" value="no" />
<form  class="layui-form layui-form-pane1" id="subform" method="post">

    <input type="hidden" id="info_id" name="info_id" value=${param.info_id} />


    <div class="layui-form-item">
        <label class="layui-form-label">资讯标题</label>
        <div class="layui-input-block">
            <input type="text" id="info_title" name="info_title" lay-verify="required|title"  placeholder="请输入标题" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">资讯类型</label>
        <div class="layui-input-block">
            <select id="info_class" name="info_class" lay-filter="adminRole" >
                <option  value="" >请选择类型</option>
                <option  value="新手学车" >新手学车</option>
                <option  value="驾考攻略">驾考攻略</option>
                <option  value="驾考常识">驾考常识</option>
                <option  value="交通法规">交通法规</option>
            </select>
        </div>
    </div>

    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">修改内容</label>
        <div class="layui-input-block">
            <textarea id="info_content" name="info_content" placeholder="请输入内容或上传文件（优先选择文件）" class="layui-textarea change_size"></textarea>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">传文修改</label>
        <div class="layui-input-block">
            <input type="file" name="file" id="file_content" accept="text/plain" />
        </div>
    </div>




</form>
<br>
<div class="layui-form-item">
    <div class="layui-input-block">
        <button class="layui-btn" id="add_btn" onclick="to_submit()" >立即修改</button>
        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
    </div>
</div>

<br><br><br>

<script>

    //加载layui信息
    layui.use('form', function(){
        var form = layui.form;
        //layui日期选择
        layui.use('laydate', function(){
            var laydate = layui.laydate;

            //执行一个laydate实例
            laydate.render({
                elem: '#createTime', //指定元素
                value: new Date()
            });
        });
    });

    layui.use('layer', function(){
        var layer = layui.layer;

    });

    window.onload=function(){
        init();
    }
    function init(){
        var info_id=$("#info_id").val();
        $.ajax({
            url:"${pageContext.request.contextPath}/info_table_edit_init.do",
            data:{
                "info_id":info_id
            },
            success:function(data,status){
                if(status=="success"){
                    $("#info_title").val(data.info_title);
                    var select = 'dd[lay-value=' + data.info_class + ']';
                    $('#info_class').siblings("div.layui-form-select").find('dl').find(select).click();
                    $("#info_content").val(data.info_content);
                }
            }
        });
    }

    function to_submit(){
        var info_title=$("#info_title").val();
        var info_class=$("#info_class").val();
        if(info_title==""){
            layer.msg("标题不能为空");
            return ;
        }
        if(info_class==""){
            layer.msg("您还没有选择类型");
            return ;
        }
        if($("#flag_manager").val()!="null"){
        if($("#file_content").val()==""||$("#file_content").val()==null)
            ajaxFile("${pageContext.request.contextPath}/info_table_edit_no_file.do");
        else
            ajaxFile("${pageContext.request.contextPath}/info_table_edit_with_file.do");
        }else{
            layer.msg("操作失败，您不是管理员");
        }

    }
    function ajaxFile(url){
        $("#subform").ajaxSubmit({
            url:url,
            type:"post",
            enctype:'multipart/form-data',
            success:function(data,status){
                if(status=="success") {
                    $("#flag_edit").val("yes");
                    $("#info_content").val(data.str);
                    layer.msg("数据已经修改", {icon: 1});
                }
            }
        })
    }

</script>

</body>
</html>

